# 载入原始数据 ----
library('arules')
library('arulesViz')
library('arulesSequences')
library('dplyr')


setwd('/Users/lz/PycharmProjects/Rlz/')
jinzhou_call_raw <- read.csv('karate_club.csv')

jinzhou_call_apri <- jinzhou_call_raw %>%  distinct(手机号码,联系号码) 

# 可以先考察是否为整型，%>%  filter(is.numeric(c(联系号码)))
#因为读入可能默认为整型的所以需要转化为字符型
jinzhou_call_apri['联系号码']=as.character(jinzhou_call_apri$联系号码)


# 按照主叫姓名聚合，同时使用，拼接在一起
jinzhou_call_apri<-jinzhou_call_apri%>%  group_by(手机号码) %>%  summarise(联系号码=paste(联系号码,collapse = ',')) 


#对主叫用户的186个呼叫用户提取作为事务，
jinzhou_call_apri_trans <- as(strsplit(jinzhou_call_apri$联系号码,','),'transactions')
# supp=184*0.03=5.52

# 0.05,0.8 5681rules
# 0.055,0.8 5681
# 0.06,0.8 16
# 0.07,0.8 16
jinzou_apriori<- apriori(jinzhou_call_apri_trans,parameter = list(supp=0.05,conf=0.8))
summary(jinzou_apriori)
inspect(jinzou_apriori)
# 每个篮子物品数量
plot(density(size(jinzhou_call_apri_trans)))
plot(jinzou_apriori,method='graph')
plot(jinzou_apriori,method='paracoord')

